import java.net.InetAddress;
/**
 * Project: SecuritySnort
 * This class will take care of tallying all the IP that are captured
 * during a listen session.
 *
 * @author Jonathan Buttner
 * @version Mar 5, 2010
 */
public class IPSaver
{
	/**************************************************************************
	 * 							Globals
	 *************************************************************************/
	private BST < InetAddComp > _tree;
	/**************************************************************************
	 * 							Constructors
	 *************************************************************************/
	/**
	 * This constructor sets up the class and tree object.
	 */
	public IPSaver()
	{
		_tree = new BST < InetAddComp >();
	}
	/**************************************************************************
	 * 							Public Methods
	 *************************************************************************/
	/**
	 * This method adds an IP address to the tree.
	 * 
	 * @param ip is an IP Address.
	 */
	public void addIP( InetAddress ip, Object mac )
	{
		String strMAC = mac.toString();
		InetAddComp dup = _tree.insert( new InetAddComp( ip, strMAC ) );
		
		//if the IP already existed in the tree then see if we actually have
		//a legit MAC address
		if ( dup != null && !strMAC.isEmpty() && dup.getMAC().isEmpty() ) 
			dup.setMAC( strMAC );
	}
	
	public void addIP( String ip, String mac )
	{
		InetAddComp dup = _tree.insert( new InetAddComp( ip, mac ) );
		
		//if the IP already existed in the tree then see if we actually have
		//a legit MAC address
		if ( dup != null && !mac.isEmpty() && dup.getMAC().isEmpty() ) 
			dup.setMAC( mac );
	}
	
	/**
	 * This method is used to print the tree Inorder.
	 * 
	 * @return a string representation of the tree.
	 */
	public String printTree()
	{
		return _tree.printInorder();
	}
	/**************************************************************************
	 * 							Private Methods
	 *************************************************************************/
}
